﻿using Code;
using Native.Sdk.Cqp.EventArgs;
using PCRRPG.Code.EconomySystem;
using System;
using System.Text.RegularExpressions;

namespace github.heerheer.card2.Code.Events
{
    internal class Event_Eco : IMessageEvent
    {
        public string Message => throw new NotImplementedException();

        public void Process(CQPrivateMessageEventArgs e)
        {
            throw new NotImplementedException();
        }

        public void Process(CQGroupMessageEventArgs e)
        {
            var str = Regex.Replace(e.Message.Text, @"\[CQ:at,qq=(.*?)\]", "$1");
            string[] arg = str.Split(' ');

            if (arg[1] == "give" && e.FromQQ.GetGroupMemberInfo(e.FromGroup).MemberType != Native.Sdk.Cqp.Enum.QQGroupMemberType.Member)
            {
                if (arg.Length < 5)
                {
                    return;
                }
                else
                {
                    if (arg[2] == "all")
                    {
                        foreach (var item in e.FromGroup.GetGroupMemberList())
                        {
                            EconomyOperater.AddMoney(item.QQ.Id, e.FromGroup.Id, arg[3], int.Parse(arg[4]));
                        }
                    }
                    else
                    {
                        EconomyOperater.AddMoney(long.Parse(arg[2]), e.FromGroup.Id, arg[3], int.Parse(arg[4]));
                    }

                    var reply = AppMain.commandHelper.EcoCommandReply.Replace("{Count}", arg[4]).Replace("{Name}", arg[3]);
                    if (reply == "")
                    {
                        e.Handler = false;
                        return;
                    }
                    e.FromGroup.SendGroupMessage(reply);
                }
            }
            if (arg[1] == "query")
            {
                if (arg.Length < 3)
                {
                    return;
                }
                else
                {
                    e.FromGroup.SendGroupMessage("开发中..");
                }
            }
        }
    }
}